﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace VideoReflector.Controllers
{
    /// <summary>
    /// Abstract base class for task based controllers which fire a Finished event upon coming to the end
    /// of the task they are associated with
    /// </summary>
    public abstract class TaskController : NotifyingObject
    {
        /// <summary>
        /// Event invoked when controller has finished task with event argument specifying
        /// whether task was cancelled by user or not
        /// </summary>
        public event EventHandler<TaskFinishedEventArgs> Finished;

        /// <summary>
        /// Raise Finished event for TaskController
        /// </summary>
        /// <param name="e"> Event arguments specifying whether task was cancelled by user or not </param>
        protected virtual void OnFinished(TaskFinishedEventArgs e)
        {
            // Make a temporary copy of the event to avoid possibility of
            // a race condition if the last subscriber unsubscribes
            // immediately after the null check and before the event is raised.
            var handler = Finished;
            if (handler != null)
            {
                handler(this, e);
            }
        }
    }
}